import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/app_colors.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_page/pre_sale/pre_sale_provider.dart';
import 'package:tiktokadult/tools_base/global_store/store.dart';

import 'ai_main_page.dart';
import 'gril_friend/ai_girl_friend_page.dart';

class AIEnterModel {
  String? bg;
  String? titleImg;
  String? title;
  String? subTitle;
  String? desc;

  AIEnterModel({
    this.bg,
    this.titleImg,
    this.title,
    this.subTitle,
    this.desc,
  });
}

//ai入口
class AiHomeMenuPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _AiHomeMenuPageState();
  }
}

class _AiHomeMenuPageState extends State<AiHomeMenuPage> {
  List<AIEnterModel> dataList = [];

  @override
  void initState() {
    super.initState();
    presaleProvider.refreshPreSalStatus(); //刷新预售权益
    globalStore.refreshWallet(); //刷新钱包
    dataList.add(AIEnterModel(
      bg: 'ai_main_bg1.gif'.aiPath,
      titleImg: 'ai_main_friend.png'.aiPath,
      title: 'AI女友 ',
      subTitle: '(聊天)',
      desc: '暖心陪伴 您的专属女友',
    ));
    dataList.add(AIEnterModel(
      bg: 'ai_main_bg2.gif'.aiPath,
      titleImg: 'ai_main_img.png'.aiPath,
      title: 'AI换脸 ',
      subTitle: '(图片)',
      desc: 'AI换脸，玩出新花样',
    ));
    dataList.add(AIEnterModel(
      bg: 'ai_main_bg3.gif'.aiPath,
      titleImg: 'ai_main_video.png'.aiPath,
      title: 'AI换脸 ',
      subTitle: '(视频)',
      desc: '轻松换脸，趣味无穷',
    ));
    dataList.add(AIEnterModel(
      bg: 'ai_main_bg4.gif'.aiPath,
      titleImg: 'ai_main_cloth.png'.aiPath,
      title: 'AI脱衣 ',
      subTitle: '(图片)',
      desc: '在你面前一丝不挂',
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("AI科技")),
      body: ListView.separated(
        padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
        itemBuilder: (context, index) => _buildItem(index),
        separatorBuilder: (context, index) => const SizedBox(height: 12),
        itemCount: dataList.length,
      ),
    );
  }

  _buildItem(int index) {
    return GestureDetector(
      onTap: () {
        if (index == 0) {
          Get.to(() => const AIGrilFriendPage());
        } else {
          final indexs = [1, 0, 2];
          Get.to(() => AiPage(tabIndex: indexs[index - 1]));
        }
      },
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          color: Colors.black.withOpacity(.04),
        ),
        child: Column(
          children: [
            Stack(
              children: [
                ClipRRect(
                  borderRadius: const BorderRadius.only(
                    topLeft: Radius.circular(8),
                    topRight: Radius.circular(8),
                  ),
                  child: Image.asset(
                    '${dataList[index].bg}',
                  ),
                ),
                Positioned(
                  bottom: 10,
                  left: 10,
                  child: Text(
                    '${dataList[index].desc}',
                    style: TextStyle(
                      fontSize: 14,
                      color: Colors.white,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ),
                if (index == 0)
                  Positioned(
                    right: 0,
                    top: 0,
                    width: 100,
                    child: Image.asset('ai_badge.png'.aiPath),
                  )
              ],
            ),
            const SizedBox(height: 14),
            _buildItemRow(index, index != 0),
            const SizedBox(height: 12),
          ],
        ),
      ),
    );
  }

  _buildItemRow(int index, bool showBeta) {
    return Row(
      children: [
        const SizedBox(width: 16),
        Image.asset(
          '${dataList[index].titleImg}',
          width: 15,
          color: AppColors.actionRed,
        ),
        const SizedBox(width: 6),
        RichText(
          //文字居中
          textAlign: TextAlign.center,
          //文字区域
          text: TextSpan(
            text: dataList[index].title,
            style: TextStyle(
              fontSize: 17,
              color: Color(0xff999999),
              fontWeight: FontWeight.w500,
            ),
            children: [
              TextSpan(
                text: dataList[index].subTitle,
                style: const TextStyle(color: AppColors.actionRed, fontSize: 13),
              ),
            ],
          ),
        ),
        const SizedBox(width: 8),
        // if (showBeta)
        //   Container(
        //     padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
        //     decoration: BoxDecoration(
        //       borderRadius: BorderRadius.circular(16),
        //       border: Border.all(width: 0.5, color: AppColors.actionRed),
        //     ),
        //     child: Text(
        //       'beta',
        //       style: TextStyle(
        //         fontSize: 12,
        //         color: AppColors.actionRed,
        //         fontWeight: FontWeight.w400,
        //       ),
        //     ),
        //   )
      ],
    );
  }
}
